package com.hf.service.impl;

import com.hf.dao.UserDao;
import com.hf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

//<bean id="userService" class="com.hf.service.impl.UserServiceImpl">
//@Component("userService") //一眼看上去不知道是哪个层的
@Service("userService")
//@Scope("prototype")
@Scope("singleton")
public class UserServiceImpl implements UserService {

    @Value("${jdbc.driver}")
    private String driver;

    //   <property name="userDao"ref="userDao"></property>
//    @Autowired //按照类型从Spring容器中进行匹配
//    @Qualifier("userDao") //按照id名从容器中进行匹配的，注意此处@Qualifier要结合@Autowired一块使用
    @Resource(name = "userDao") //相当于@Qualifier＋@Autowired
    private UserDao userDao;

//    如果使用注解开发，可以省略掉xml配置需要的set方法
//    public void setUserDao(UserDao userDao) {
//        this.userDao = userDao;
//    }

    public void say() {
        userDao.say();
        System.out.println(driver);
    }
}
